package com.zyf.chapter01.practice.v3;

import com.zyf.chapter01.practice.v2.StatViewer;
import com.zyf.chapter01.principle.practice.EmailSender;
import com.zyf.chapter01.principle.practice.RequestStat;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 显示终端 邮件实现
 * 第三个逻辑：将统计数据显示到终端
 * @author yifeng
 * @since v3
 */
public class EmailViewer implements StatViewer {
    private static final Long DAY_HOURS_IN_SECONDS = 86400L;

    private EmailSender emailSender;
    private List<String> toAddresses = new ArrayList<>();

    public EmailViewer() {
        emailSender = new EmailSender(/* 省略参数 */);
    }

    public EmailViewer(EmailSender emailSender) {
        this.emailSender = emailSender;
    }

    public EmailViewer(List<String> toAddresses) {
        this.toAddresses = toAddresses;
    }

    public void addToAddress(String address) {
        toAddresses.add(address);
    }

    @Override
    public void output(Map<String, RequestStat> requestStat, long statTimeInMillis, long endTimeInMillis) {
        // format the requestStats to HTML style.
        // send it to email toAddress.
    }
}
